package com.hanbang.chu_xing_gao_zhao.base;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.onekeyshare.OnekeyShare;

import com.hanbang.chu_xing_gao_zhao.application.ActivityManager;
import com.hanbang.chu_xing_gao_zhao.application.HttpInterfaces;
import com.hanbang.chu_xing_gao_zhao.application.MyApplication;
import com.hanbang.chu_xing_gao_zhao.entity.PositionData;
import com.hanbang.chu_xing_gao_zhao.entity.UserInforData;
import com.hanbang.chu_xing_gao_zhao.module.LogInActivity;
import com.hanbang.chu_xing_gao_zhao.utils.BitmapUtil;
import com.hanbang.chu_xing_gao_zhao.utils.DbUtil;
import com.hanbang.chu_xing_gao_zhao.utils.JsonHelper;
import com.hanbang.chu_xing_gao_zhao.utils.MyLog;
import com.hanbang.chu_xing_gao_zhao.utils.MyRequestCallBack;
import com.hanbang.chu_xing_gao_zhao.utils.MySharedPreferences;
import com.hanbang.chu_xing_gao_zhao.utils.MyToast;
import com.hanbang.chu_xing_gao_zhao.utils.UiUtils;
import com.hanbang.chu_xing_gao_zhao.view_city_select.ItemCityData;
import com.hanbang.cxgz_2.R;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.DbUtils;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.DbException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;

public class MainDataActivity extends MainActivity {

	/**
	 * 年龄-数组
	 */
	public ArrayList<PositionData> ageArrayList = new ArrayList<PositionData>();

	/**
	 * 菜系-数组
	 */
	public ArrayList<PositionData> styleOofCookingList = new ArrayList<PositionData>();

	/**
	 * 职位-数组
	 */
	public ArrayList<PositionData> positionList = new ArrayList<PositionData>();;

	/**
	 * 城市-数据
	 */
	public ArrayList<ItemCityData> cityDataList = new ArrayList<ItemCityData>();

	/**
	 * 最热-数据
	 */
	public ArrayList<PositionData> hottestList = new ArrayList<PositionData>();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		addAgeData();
		getPositionData();
		getSytleOfCookingData();
		addHottstData();

	}

	/**
	 * 添加 年龄 数组
	 */
	public void addAgeData() {

		if (ageArrayList.size() != 0) {
			return;
		}
		PositionData data;
		for (int i = 0; i <= 82; i++) {
			data = new PositionData(0, (18 + i) + "", 0, null);
			ageArrayList.add(data);

		}
	}

	/**
	 * 添加 最热 数组
	 */
	public void addHottstData() {
		if (hottestList.size() != 0) {
			return;
		}
		hottestList.add(new PositionData(0, "全部", 0, null));
		hottestList.add(new PositionData(0, "秘籍最多", 0, null));
		hottestList.add(new PositionData(0, "粉丝最多", 0, null));

	}

	/**
	 * 从接口中获取，职位 列表
	 */
	private void getPositionData() {
		if (positionList.size() != 0) {
			return;
		}

		// TODO Auto-generated method stub
		httpUtils.send(HttpMethod.GET, HttpInterfaces.GetJobList, new MyRequestCallBack<String>(this, "加载职位列表...") {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				super.onSuccess(responseInfo);
				try {
					JSONObject json = new JSONObject(responseInfo.result);

					int status = json.getInt("Result");
					if (status == 0) {
						// 把jso 转换成数组
						JSONArray relate = json.getJSONArray("list");

						for (int i = 0; i < relate.length(); i++) {
							// 得到数组中的每一个对象
							JSONObject relateItem = relate.getJSONObject(i);
							// data赋值
							PositionData data = JsonHelper.parseObject(relateItem, PositionData.class);
							// 添加到集合中
							positionList.add(data);

						}

					} else {

					}

				} catch (JSONException e) {
					e.printStackTrace();

				}

			}
		});
	}

	/**
	 * 从接口中获取，菜系 列表
	 */
	public void getSytleOfCookingData() {
		if (styleOofCookingList.size() != 0) {
			return;
		}
		// TODO Auto-generated method stub
		httpUtils.send(HttpMethod.GET, HttpInterfaces.GetPositionList,
				new MyRequestCallBack<String>(this, "加载菜系列表...") {
					@Override
					public void onSuccess(ResponseInfo<String> responseInfo) {
						super.onSuccess(responseInfo);
						try {
							JSONObject json = new JSONObject(responseInfo.result);

							int status = json.getInt("Result");
							if (status == 0) {
								// 把jso 转换成数组
								JSONArray relate = json.getJSONArray("list");

								for (int i = 0; i < relate.length(); i++) {
									// 得到数组中的每一个对象
									JSONObject relateItem = relate.getJSONObject(i);
									// data赋值
									PositionData data = JsonHelper.parseObject(relateItem, PositionData.class);
									// 添加到集合中
									styleOofCookingList.add(data);

								}

							} else {

							}

						} catch (JSONException e) {
							e.printStackTrace();
						}

					}
				});
	}

}
